package wiki.generic.iotests;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import wiki.generic.io.User;
import wiki.generic.io.UsersWriter;

/**
 * @author <p><strong>JwTeam</strong></p> 
 * 
 * La classe ConcreteDataWriter implementa il metodo per salvare i dati degli utenti su file
 */
public class ConcreteUsersWriter implements UsersWriter {


	@Override
	public void saveUsers(HashMap<String, User> map,String destinationfile){

		File file = new File(destinationfile);
		try {
			BufferedWriter writer=new BufferedWriter(new FileWriter(file));
			Set<String> keys=map.keySet();
			for (Iterator<String> iterator = keys.iterator(); iterator.hasNext();) {
				String key=iterator.next();
				User user=map.get(key);
				String nome = user.getNome();
				String cognome = user.getCognome();
				String pwd = user.getPassword();
				String corso = user.getCorso();
				String email = user.getEmail();
				boolean isDoc = user.isDocente();
				boolean fA = user.isFirstAccess();
				writer.write(nome + "$$||$$" + cognome + "$$||$$" + pwd + "$$||$$" + corso + "$$||$$"
						+ email + "$$||$$" + isDoc + "$$||$$" + fA + "\n");
			}				
			writer.close();			
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
